package com.wpl.fastec.fastec;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.wpl.fastec.latte.core.fragments.LatteFragment;
import com.wpl.fastec.latte.core.net.RestClient;
import com.wpl.fastec.latte.core.net.callback.IError;
import com.wpl.fastec.latte.core.net.callback.IFailure;
import com.wpl.fastec.latte.core.net.callback.ISuccess;

public class ExampleFragment extends LatteFragment {
    @Override
    public Object setLayout() {
        return R.layout.fragment_example;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        testRestClient();
    }

    private void testRestClient(){
        RestClient.builder()
                .url("https://news.baidu.com/")
                .loader(getContext())
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        Toast.makeText(getContext(),response,Toast.LENGTH_LONG).show();
                    }
                })
                .failure(new IFailure() {
                    @Override
                    public void onFailure() {
                        Toast.makeText(getContext(), "onFailure",Toast.LENGTH_LONG).show();
                    }
                }).error(new IError() {
            @Override
            public void onError(int code, String msg) {
                Toast.makeText(getContext(),"onError",Toast.LENGTH_LONG).show();
            }
        }).build()
        .get();
    }
}
